import { createStore } from 'vuex'
import type { UserInfoVuexTypes } from '@/server/serve/api_admintor'

const Background = {
  Dark: {
    backgroundColor: '#212130',
    color: '#fff'
  },
  Light: {
    backgroundColor: '#fff',
    color: '#000'
  }
}

export default createStore({
  state: {
    // 用户信息
    userInfo: {} as UserInfoVuexTypes,
    // 主题背景颜色
    Background: Background.Light
  },
  mutations: {
    // 存入信息
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    // 退出登录 清除信息
    clearUserInfo(state) {
      state.userInfo = {} as UserInfoVuexTypes
    },
    // 切换背景颜色
    switchBGColor(state, nowBgcColor) {
      if (nowBgcColor) {
        state.Background = nowBgcColor
      } else {
        if (state.Background.backgroundColor === '#fff') {
          state.Background = Background.Dark
        } else {
          state.Background = Background.Light
        }
      }
    }
  },
  actions: {},
  modules: {}
})
